layui.use(['table','layer','form','laydate','common'], function(){
	var table = layui.table,layer = layui.layer,$ = layui.$,laydate = layui.laydate,form = layui.form;
	var common = layui.common;
	
	/*@时间*/
	/*开始时间*/
	laydate.render({
	  	elem: '#start' //指定元素
	});
	/*结束时间*/
	laydate.render({
	  	elem: '#end' //指定元素
	});
	/*@配件返库历史初始化table*/
	var tableObj = table.render({
	    elem: '#log-table-list',
	    url: '/repair/stock/log_list', //数据接口
	    id: 'table_list',
	    page: true, //开启分页
	    cols: [[ //表头
	    	{field: 'id', title: '序号', type: 'checkbox'},
	    	{field: 'ret_time', title: '返库时间'},
	    	{field: 'goods_name', title: '产品名称'},
	    	{field: 'repair_sn', title: '相关维修订单编号'},
	    	{field: 'number', title: '数量'},
	    	{field: 'unit', title: '单位'},
	    	{field: 'selling_price', title: '零售单价（元）'},
	    	{field: 'trade_price', title: '批发价（元）'},
	    	{field: 'buying_price', title: '进货价（元）'},
	    	{field: 'position_text', title: '原所在位置'},
	    ]],
	    /*渲染前，请求成功后回调*/
	    parseData: function(res){
	    	if(res.code === 0){
	    		var num = (res.page-1) * res.row
		    	for(var i = 0;i < res.data.length;++i){
		    		res.data[i].id = num + i + 1
		    	}
		    	exportData = res.data
	    	}
	    }
	});
	/*@select选择监听*/
	form.on('select(select)',function(data){
		if(data.value == ''){
			$('select[name="brand_name"]').html('')
			$('select[name="memory_name"]').html('')
			$('select[name="attribute_name"]').html('')
			$('select[name="colour_name"]').html('')
			form.render("select");
			return
		}
		$.post('/repair/stock/get_attribute',{fid: data.value},function(msg){
			if(msg.code === 1){
				for(var k in msg.data){
					var html = '<option value="">全部</option>';
					for(var i = 0;i < msg.data[k].length;++i){
						html += '<option value="'+msg.data[k][i].attribute_name+'">'+msg.data[k][i].attribute_name+'</option>';
					}
					$('select[name="'+k+'"]').html(html)
				}
				form.render("select");
			}else{
				layer.msg(msg.msg, {icon: 5, time: 2000})
			}
		})
	})
	/*@导出数据处理*/
	common.list.handleData = function(res){
		for(var i = 0;i < res.data.length;++i){
    		res.data[i].id = i + 1
    	}
    	return res.data
	}
	/*@查询*/
	common.list.search('search', tableObj)
	/*@导出*/
	common.list.excel('export', '/repair/stock/log_list', tableObj, '维修配件返库历史', 'xls')


})